#include<bits/stdc++.h>
using namespace std;
namespace IO{
    const int BUF=1<<21;
    char buff[BUF],*p1=buff,*p2=buff;
    #define getchar() (p1==p2&&(p2=((p1=buff)+fread(buff,1,BUF,stdin)),p1==p2)?EOF:*p1++)
    template<typename T>inline void read(T &x){
        char ch=getchar();x=0;int f=1;
        while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
        while(isdigit(ch)) x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
        x*=f;
    }
    char obuf[BUF],*p3=obuf;
    inline void pc(char ch){
        if(p3-obuf<BUF) *p3++=ch;
        else fwrite(obuf,p3-obuf,1,stdout),p3=obuf,*p3++=ch;
    }
    char ch[32],ctop;
    template<typename T>inline void print(T x){
    	if(x<0) x=~x+1,pc('-');
        if(!x) return pc(48);
        while(x) ch[++ctop]=x%10^48,x/=10;
        while(ctop) pc(ch[ctop--]);
    }
    inline void flush(){fwrite(obuf,p3-obuf,1,stdout);}
}
using namespace IO;
const int N=3e5+5,mod=998244353;
int n,a[N],b[N];
bool sub=1;
int ans;
const int P1=2333,P2=147744151;
map<pair<int,int>,bool> vis;
void dfs(int x){
	if(x==n+1){
		int v1=0,v2=0,mul=1;
		for(int i=1;i<=n;++i){
			int val=a[i]+b[(i==1?n:i-1)]-b[i];
			mul=1ll*mul*val%mod;
			v1=(1ll*v1*P1+val)%mod;
			v2=(1ll*v2*P2+val)%mod;
		}
		if(!vis[{v1,v2}]){
			vis[{v1,v2}]=1;
			ans=(ans+mul)%mod;
		}
		return;
	}
	for(b[x]=0;b[x]<=a[x];++b[x]) dfs(x+1); 
}
int main(){
	freopen("trade.in","r",stdin);
	freopen("trade.out","w",stdout);
	read(n);
	for(int i=1;i<=n;++i) read(a[i]),sub&=(a[i]<=1);
	if(sub){
		ans=1;
		for(int i=1;i<=n;++i) ans*=a[i];
		cout<<ans;
		return 0;
	}
	dfs(1);
	cout<<ans;
	return 0;
}

